package com.lx.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lx.beans.Student;
import com.lx.service.StudentService;

@Controller
@RequestMapping("stu")
public class StudentController {

	@Autowired
	@Qualifier("studentServiceImpl2")
	private StudentService sService;

	@RequestMapping("list")
	public String list(Map<String, Object> map) {
		// 查询所有学生，
		List<Student> sList = sService.findAllStus();
		map.put("sList", sList);
		// 返回到模板页面
		return "list";
	}

	/**
	 * 测试添加缓存功能
	 * @param id
	 * @param map
	 * @return
	 */
	@RequestMapping("/find/{id}")
	public String findById(@PathVariable("id") Integer id,Map<String, Object> map) {
		Student s = sService.findById(id);
		map.put("stu", s);
		return "detail";
	}
	
	@RequestMapping("remove/{id}")
	public String removeCache(@PathVariable("id") Integer id){
		sService.remove(id);
		return "redirect:/stu/list";
	}

	@RequestMapping("removeAll")
	public String removeCache(){
		sService.deleteAll();
		return "redirect:/stu/list";
	}
	
	@RequestMapping("/refresh/{id}")
	public String refresh(@PathVariable("id") Integer id,Map<String, Object> map) {
		Student s = sService.refresh(id);
		map.put("stu", s);
		return "detail";
	}
}
